#include <cppunit/config/SourcePrefix.h>
#include "ModifiesTest.h"
#include "Parser.h"
#include "PKB.h"
#include <iostream>
#include <string>
#include <set>

using namespace std;

void ModifiesTest::setUp() {}
void ModifiesTest::tearDown() {}

CPPUNIT_TEST_SUITE_REGISTRATION( ModifiesTest );


// method to test the setting and retrieval of Modifies relationship
void ModifiesTest::testSetModifiesStmtAndGetModifiedByStmt() 
{
	cout << "Testing : void setModifiesStmtModifies(INDEX, INDEX)" << endl;
	cout << "and INDEX_SET getModifiedByStmt(INDEX)" << endl;
	VarTable* vt;
	StmtTable *st;
	ProcTable *pt;
	vt = new VarTable();
	st = new StmtTable();
	pt = new ProcTable();
	modifies = new Modifies(vt, st, pt);
	set<int> indexSet;
	// set some Modifies relationship
	modifies->setModifiesStmtModifies(7, 2);
	modifies->setModifiesStmtModifies(10, 2);
		
	// verify that the assignment is corrects
	indexSet = modifies->getModifiedByStmt(7);
	CPPUNIT_ASSERT_EQUAL(2, *indexSet.begin());

	indexSet = modifies->getModifiedByStmt(10);
	CPPUNIT_ASSERT_EQUAL(2, *indexSet.begin());
	
	// attempt to retrieve a stmt that does not exist
	//count = modifies->getModifiedByStmt(23);

	cout << "Test OK  : void setModifiesStmtModifies(INDEX, INDEX)" << endl;
	cout << "and INDEX_SET getModifiedByStmt(INDEX)" << endl;
}

void ModifiesTest::testHasEntryFirstParamModifies()
{
	cout << "Testing : bool hasEntryFirstParamModifies(INDEX)" << endl;
	VarTable* vt;
	StmtTable *st;
	ProcTable *pt;
	vt = new VarTable();
	st = new StmtTable();
	pt = new ProcTable();
	modifies = new Modifies(vt, st, pt);
	// set some Modifies relationship
	modifies->setModifiesStmtModifies(7, 2);
	modifies->setModifiesStmtModifies(10, 2);

	//CPPUNIT_ASSERT(modifies->hasModifies(7,-1));
	//CPPUNIT_ASSERT(!modifies->hasModifies(1,-1));

	cout << "Test OK  : bool hasEntryFirstParamModifies(INDEX)" << endl;
}

